#include "at32f435_437_board.h"
#include "at32f435_437_clock.h"

#include "u8g2.h"
#include "u8g2_hal.h"

#include "button_hal.h"
#include "oled_menu.h"
#include "buzzer_control.h"

u8g2_t u8g2;

int main(void)
{
  system_clock_config();
  nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);

  at32_board_init();
  uart_print_init(230400);
  
  buzzer_init();
  user_button_init();
  
  disp_i2c_init();
  u8g2_Setup_sh1106_i2c_128x64_noname_f(
    &u8g2,
    U8G2_R2,
    u8x8_byte_i2c,
    u8x8_gpio_and_delay);  // init u8g2 structure
  u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
  u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,
  u8g2_SetPowerSave(&u8g2, 0); // wake up display
  u8g2_SetContrast(&u8g2, 0x01);
  u8g2_ClearDisplay(&u8g2);
  
  menu_init();

  while(1)
  {

  }
}
